package cn.mw.cmdb.service.impl;

import cn.mw.cmdb.entity.InstanceMetricInfo;
import cn.mw.cmdb.mongoMapper.InstanceMetricInfoMapper;
import cn.mw.cmdb.param.InstanceMetricInfoIdsParam;
import cn.mw.cmdb.util.CMDBTool;
import cn.mw.components.mongodb.tool.CriteriaWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

@Slf4j
public class InstanceMetricServiceImpl extends ModelBaseServiceImpl<InstanceMetricInfo, Object> {

    public static final String ID = "instanceMetricService";

    private final CmdbServiceManage cmdbServiceManage;

    private final InstanceMetricInfoMapper instanceMetricInfoMapper;

    public InstanceMetricServiceImpl(CmdbServiceManage cmdbServiceManage, InstanceMetricInfoMapper instanceMetricInfoMapper) {
        this.cmdbServiceManage = cmdbServiceManage;
        this.instanceMetricInfoMapper = instanceMetricInfoMapper;
    }

    @Override
    public InstanceMetricInfo genObject() {
        return new InstanceMetricInfo();
    }

    @Override
    Object doAdd(InstanceMetricInfo param) throws Exception {
        return null;
    }

    @Override
    boolean doUpdate(InstanceMetricInfo param) throws Exception {
        return false;
    }

    @Override
    boolean doRemove(InstanceMetricInfo param) throws Exception {
        return false;
    }

    @Override
    Object doBatchAdd(Object params) throws Exception {
        return null;
    }

    @Override
    boolean doBatchUpdate(Object params) throws Exception {
        return false;
    }

    @Override
    InstanceMetricInfo doSelectById(Object id) throws Exception {
        return null;
    }

    @Override
    List<InstanceMetricInfo> doSelectList(Object params) throws Exception {
        InstanceMetricInfoIdsParam param = (InstanceMetricInfoIdsParam) params;
        Criteria criteria = new Criteria();
        if (param != null && param.getInstanceIds() != null) {
            criteria = CriteriaWrapper.where(InstanceMetricInfo::getInstanceId).in(param.getInstanceIds());
        }
        Query query = new Query(criteria);
        List<InstanceMetricInfo> ret = CMDBTool.selectList(InstanceMetricInfo.class, instanceMetricInfoMapper, query, param);

        return ret;
    }

    @Override
    boolean doBatchRemove(Object params) throws Exception {
        return false;
    }

    public InstanceMetricInfo getAlgorithmByInstanceId(String instanceId) throws Exception {
        Criteria criteria = CriteriaWrapper.where(InstanceMetricInfo::getInstanceId).is(instanceId);
        Query query = Query.query(criteria);
        InstanceMetricInfo one = instanceMetricInfoMapper.findOne(query);
        return one;
    }
}
